//
//  CSLabelView.m
//  市场监管通
//
//  Created by 网新中研 on 16/4/18.
//  Copyright © 2016年 centralsoft. All rights reserved.
//

#import "CSLabelView.h"
#import "Common.h"
#import "CS_Page_TextView.h"



@interface CSLabelView()

@property (nonatomic, strong) UILabel *dataLabel;

@property (nonatomic, strong) UIView *seperatorLine;

@property (nonatomic, strong) CS_Page_TextView *page_TextvIEW;

@end

@implementation CSLabelView

-(NSInteger)viewType{
    return CSViewType_PageTextView;
}

+(instancetype)labelViewWithDescriptionTitle:(NSString *)descriptionTitle data:(NSString *)data{
    
    CSLabelView *label = [CSLabelView new];
    descriptionTitle = [descriptionTitle replaceCharcter:@"：" withCharcter:@""];
    label.page_TextvIEW = [CS_Page_TextView page_textView:descriptionTitle dataValue:data];
    return label;
    
    label.descriptionTitle = descriptionTitle;
    label.data = data;
    return label;
}

-(CGFloat)layoutView:(UIView *)superView primaryY:(CGFloat)primaryY{
    
    return [_page_TextvIEW layoutView:superView primaryY:primaryY];
    
    
    CGFloat localY = primaryY;
    
    //标题
    CGFloat estimateDescriptionHeight = [self estimateHeight:self.descriptionTitle font:self.descriptionLabel.font width:CELL_TITLE_WIDTH];
    CGFloat finalDescriptionHeight = estimateDescriptionHeight > CELL_LABLE_HEIGHT? estimateDescriptionHeight : CELL_LABLE_HEIGHT;
    self.descriptionLabel.frame = CGRectMake(0, primaryY + CELL_TOP_MARGIN, CELL_TITLE_WIDTH, finalDescriptionHeight);
    self.descriptionLabel.text = [self isNullOrEmpty:self.descriptionTitle] ? @"" : [NSString stringWithFormat:@"%@", self.descriptionTitle];
    
    //值
    CGFloat estimateDataHeight = [self estimateHeight:self.data font:self.dataLabel.font width:kWindowW - CELL_TITLE_WIDTH - CELL_RIGHT_MARGIN];
    CGFloat finalDataHeight = estimateDataHeight > CELL_LABLE_HEIGHT? estimateDataHeight : CELL_LABLE_HEIGHT;
    self.dataLabel.frame = CGRectMake(CELL_TITLE_WIDTH, primaryY + CELL_CONTENT_MARGIN_HEIGHT, kWindowW - CELL_TITLE_WIDTH - CELL_RIGHT_MARGIN, finalDataHeight);
    self.dataLabel.text = self.data;
    
    [superView addSubview:self.descriptionLabel];
    [superView addSubview:self.dataLabel];
    
    localY = primaryY + CELL_CONTENT_MARGIN_HEIGHT + (finalDescriptionHeight > finalDataHeight ? finalDescriptionHeight:finalDataHeight) + CELL_CONTENT_MARGIN_HEIGHT;
    
    self.seperatorLine.frame = CGRectMake(CELL_SEPERATOR_MARGIN_LEFT, localY, kWindowW - CELL_SEPERATOR_MARGIN_LEFT, CELL_SEPERATOR_LINE_HEIGHT);
    
    [superView addSubview:self.seperatorLine];
    
    return [super layoutView:superView primaryY:localY + CELL_SEPERATOR_LINE_HEIGHT];
}

-(void)setSeperateKeyString:(NSString *)seperateKeyString{
    super.seperateKeyString = seperateKeyString;
    self.page_TextvIEW.seperateKeyString = seperateKeyString;
}

-(NSString *)value{
    
    return _page_TextvIEW.value;
    
    return self.dataLabel.text == nil ? @"":self.dataLabel.text;
}

- (UILabel *)dataLabel {
	if(_dataLabel == nil) {
		_dataLabel = [[UILabel alloc] init];
        _dataLabel.font = [UIFont boldSystemFontOfSize:FONT_SIZE_REM];
        _dataLabel.textColor = [UIColor blackColor];
        _dataLabel.numberOfLines = 0;
	}
	return _dataLabel;
}

- (UIView *)seperatorLine {
	if(_seperatorLine == nil) {
		_seperatorLine = [[UIView alloc] init];
        STYLE_SEPERATOR_LINE(_seperatorLine);
	}
	return _seperatorLine;
}


@end
